// UVa213 ACM/ICPC World Finals 1991 - San Antonio, Message Decoding
// 刘汝佳
// 此版本保留调试语句
#include<cstdio>
#include<cstring>

int readchar() {
  while (true) {
    int ch = getchar();
    if (ch != '\n' && ch != '\r') return ch;
  }
}

int read_bin_int(int len) {
  int v = 0;
  while (len--) v = v * 2 + readchar() - '0';
  return v;
}

int code[8][1 << 8];

int readcodes() {
  memset(code, 0, sizeof(code));
  code[1][0] = readchar();
  for (int len = 2; len <= 7; len++) {
    for (int i = 0; i < (1 << len) - 1; i++) {
      int ch = getchar();
      if (ch == EOF) return 0;
      if (ch == '\n' || ch == '\r') return 1;
      code[len][i] = ch;
    }
  }
  return 1;
}

// 用于调试
void printcodes() {
  for (int len = 1; len <= 3; len++)
    for (int i = 0; i < (1 << len) - 1; i++) {
      if (code[len][i] == 0) return;
      printf("code[%d][%d] = %c\n", len, i, code[len][i]);
    }
}

int main() {
  while (readcodes()) {
    while (true) {
      int len = read_bin_int(3);
      if (len == 0) break;
      while (true) {
        int v = read_bin_int(len);
        if (v == (1 << len) - 1) break;
        putchar(code[len][v]);
      }
    }
    puts("");
  }
  return 0;
}
/*
算法分析请参考: 《入门经典-第2版》例题4-4
*/
// 2625087  5152  Message Decoding  Accepted  C++11 0.012 2020-01-22 00:09:46